package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.hydrology.dto.WzyjDto;
import org.jeecg.modules.demo.hydrology.dto.YslcddyDto;
import org.jeecg.modules.demo.hydrology.entity.Wzyj;
import org.jeecg.modules.demo.hydrology.entity.Yslcddy;
import org.jeecg.modules.demo.hydrology.mapper.YslcddyMapper;
import org.jeecg.modules.demo.hydrology.mapper.YslcdssMapper;
import org.jeecg.modules.demo.hydrology.service.IYslcddyService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.mapper.SysDictItemMapper;
import org.jeecg.modules.system.mapper.SysDictMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 涌水量基础信息
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Service
public class YslcddyServiceImpl extends ServiceImpl<YslcddyMapper, Yslcddy> implements IYslcddyService {
    @Autowired
    private YslcddyMapper yslcddyMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    @Autowired
    private SysDictMapper sysDictMapper;
    @Autowired
    private SysDictItemMapper sysDictItemMapper;
    /**
     * 涌水量基础信息-分页列表查询
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<YslcddyDto> getList(Page<Yslcddy> page, QueryWrapper<Yslcddy> queryWrapper) {
        Page<Yslcddy> yslcddyPage = yslcddyMapper.selectPage(page, queryWrapper);
        List<YslcddyDto> collect = yslcddyPage.getRecords().stream().map(yslcddy -> {
            YslcddyDto yslcddyDto = new YslcddyDto();
            BeanUtils.copyProperties(yslcddy, yslcddyDto);
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", yslcddy.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            if (sysDepart != null){
                yslcddyDto.setStationName(sysDepart.getDepartName());
            }
            QueryWrapper<SysDict> sysDictQueryWrapper1 = new QueryWrapper<>();
            sysDictQueryWrapper1.eq("dict_code","sensor_type");
            SysDict sysDict1 = sysDictMapper.selectOne(sysDictQueryWrapper1);
            if (sysDict1 != null){
                QueryWrapper<SysDictItem> sysDictItemQueryWrapper1 = new QueryWrapper<>();
                sysDictItemQueryWrapper1.eq("dict_id",sysDict1.getId()).eq("item_value",yslcddy.getSensorType());
                SysDictItem sysDictItem1 = sysDictItemMapper.selectOne(sysDictItemQueryWrapper1);
                if (sysDictItem1 != null) {
                    yslcddyDto.setSensorTypeItemText(sysDictItem1.getItemText());
                }
            }
            return yslcddyDto;
        }).collect(Collectors.toList());
        IPage<YslcddyDto> yslcddyDtoIPage = new Page<>();
        yslcddyDtoIPage.setRecords(collect);
        yslcddyDtoIPage.setTotal(yslcddyPage.getTotal());
        yslcddyDtoIPage.setPages(page.getPages());
        yslcddyDtoIPage.setSize(page.getSize());
        return yslcddyDtoIPage;
    }
}
